package ThreadTest;

public class TestDemo2 {
    public static void main(String[] args) {
        Object object = new Object();
        Thread thread1 = new Thread(()-> {
            synchronized (object) {
                System.out.println("thread1开始");
                try {
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("thread1结束");
            }
        });
        thread1.start();//启动thread1线程

        Thread thread2 = new Thread(()-> {
            synchronized (object) {
                System.out.println("thread2开始");
                object.notify();
                System.out.println("thread2结束");
            }
        });
        thread2.start();//启动thread2线程
    }
}
